package com.example.verification.config;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;

/**
 * @author rcl
 * @date 2019/6/13 17:25
 */
@Service
public class SpringUtils1 implements ApplicationListener<ContextRefreshedEvent> {
    private static ApplicationContext applicationContext = null;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if (applicationContext == null){
            applicationContext = event.getApplicationContext();
        }
    }
    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }
    public static <T> T getBean(Class<T> clazz) {
        return applicationContext.getBean(clazz);
    }
}
